/* 2013-3-29 yzw last
*  msg
*  消息
*/

var Dialog = function()
{
	var D = this;
	D.Init = function()
	{
		D.width = 500;
		D.height = 200;
		D.speed = 10;
		D.title = "消息提示框";
		D.id = 'msgbox';
	}

	D.say = function(msg)
	{
		D.clear();
		D.addBox(msg);
		D.show();
	}

	D.addBox = function(msg)
	{
		$('body').append('<div id="'+D.id+'" style="width:'+D.width+'px;"><div class="title">'+D.title+'</div><div><p>'+msg+'</p></div><a href="javascript:;" onclick ="Dialog.close();" class="close">[关闭]</a></div>');
		D.obj = $('#'+D.id);
		D.position();
	}

	D.position = function()
	{
		var width_1 = D.obj.width();		
		var width_2 = $(window).width();
		var left = Math.ceil((width_2-width_1)/2);
		var height_1 = D.obj.height();		
		var height_2 = $(window).height();
		var top = Math.ceil((height_2-height_1)/4);
		D.obj.css({'left':left,'top':top});
	}
	
	D.show = function()
	{
		clearInterval(D.proy);
		D.proy = setInterval(function(){D.openy(D.height)},10);
	}

	D.openy = function(height)
	{
		var cy = D.obj.height();
		cy < height ? D.obj.height(cy + Math.ceil((height-cy)/15)) : clearInterval(D.proy);
	}

	D.close = function()
	{
		clearInterval(D.proy);
		clearInterval(D.proxc);
		clearInterval(D.proyc);		
		D.proyc = setInterval(function(){D.closey()},10);			
	}
	
	D.closey = function()
	{
		var cy = D.obj.height();
		cy > 0 ? D.obj.height(cy - Math.ceil(cy/5)) : (clearInterval(D.proyc),D.proxc = setInterval(function(){D.closex()},10),D.obj.css('borderWidth',1));
	}
	
	D.closex = function()
	{		
		var cx = D.obj.width();
		var cl = D.obj.offset().left + Math.ceil(cx/10);
		cx > 0 ? D.obj.css('left',cl).width(cx - Math.ceil(cx/5)):(clearInterval(D.proxc),D.clear());
	}

	D.clear = function()
	{
		typeof(D.obj)!='undefined'?D.obj.detach():'';
	}
}


	

	